package com.hnmqet.demo03.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnmqet.demo03.dao.StorageTblMapper;
import com.hnmqet.demo03.entity.StorageTbl;
import com.hnmqet.demo03.service.StorageTblService;
import io.seata.core.context.RootContext;
import io.seata.spring.boot.autoconfigure.properties.client.LockProperties;
import io.seata.spring.boot.autoconfigure.properties.client.UndoProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author td
 * @since 2020-01-07
 */
@Service
@Slf4j
public class StorageTblServiceImpl extends ServiceImpl<StorageTblMapper, StorageTbl> implements StorageTblService {
    @Autowired
    StorageTblMapper storageTblMapper;
    @Autowired
    UndoProperties undoProperties;
    @Autowired
    LockProperties lockProperties;

    @Override
    @Transactional
    public void test(String code, Integer count) {
        log.info("==============================Assign Service Begin ... xid: " + RootContext.getXID() + "\n");
        StorageTbl storageTbl = storageTblMapper.selectOne(new LambdaQueryWrapper<StorageTbl>().eq(StorageTbl::getCommodityCode, code));

        //storageTbl.setId(RandomUtil.randomInt());
        //storageTblMapper.insert(storageTbl);

        String s = undoProperties.toString();
        System.err.println("=================2222222222222222==" + undoProperties.isDataValidation());
        System.err.println("==============23333333333333333333=====" + undoProperties.isOnlyCareUpdateColumns());
        System.err.println("=============" + lockProperties.getRetryTimes());


        System.err.println(storageTbl.toString());
        storageTbl.setCount(storageTbl.getCount() - count);
        //storageTbl.setCreateTime("2020-08-28 16:55:51");
        //storageTbl.setUpdateTime("2020-08-30 16:55:52");
        storageTblMapper.update(storageTbl, new LambdaUpdateWrapper<StorageTbl>().eq(StorageTbl::getCommodityCode, "iphone11"));

        // throw  new RuntimeException();

    }
}
